<template>
  <div class="aui-card-list">
    <uni-list-query-card :queryShow="queryShow" @query-click="getDataList()" @click="(e)=>{this.queryShow=e}" @searchReset="searchReset()">
      <el-col :span="6">
        <el-form-item label="队列编码">
          <el-input v-model="dataForm.queueName" placeholder="队列编码" clearable></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="消息业务key">
          <el-input v-model="dataForm.msgBizKey" placeholder="消息业务key" clearable></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="消费状态">
          <el-select v-model="dataForm.feedStatus" placeholder="消费状态" clearable>
            <el-option :key="true" label="消费成功" :value="true"></el-option>
            <el-option :key="false" label="消费失败" :value="false"></el-option>
          </el-select>
        </el-form-item>
      </el-col>
    </uni-list-query-card>
    <el-card shadow="never" class="aui-card-list-body">
      <vxe-toolbar setting>
        <template v-slot:buttons>
        </template>
        <template v-slot:tools>
          <el-button icon="el-icon-refresh" @click="getDataList()" circle></el-button>
        </template>
      </vxe-toolbar>
      <div class="aui-card-list-body-table">
      <vxe-table ref="xTable"
                 :loading="dataListLoading"
                 class="vxe-table-element"
                 max-height="auto"
                 auto-resize
                 :data="dataList">
        <vxe-table-column type="index" align="center" width="60"></vxe-table-column>
        <vxe-table-column field="queueName" title="队列编码" width="120">
        </vxe-table-column>
        <vxe-table-column field="msgBizKey" title="消息业务key" width="180">
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row)">{{scope.row.msgBizKey}}
            </el-button>
          </template>
        </vxe-table-column>
        <vxe-table-column field="msgContent" title="消息内容json串">
        </vxe-table-column>
        <vxe-table-column field="feedStatus" title="消费状态" align="center" width="90">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.feedStatus" size="small" type="success">消费成功</el-tag>
            <el-tag v-if="!scope.row.feedStatus" size="small" type="danger">消费失败</el-tag>
          </template>
        </vxe-table-column>
        <vxe-table-column field="feedStartTime" title="开始时间" width="160">
        </vxe-table-column>
        <vxe-table-column field="feedEndTime" title="结束时间" width="160">
        </vxe-table-column>
        <vxe-table-column field="feedDuration" title="耗时(毫秒)" align="right" width="100">
        </vxe-table-column>
      </vxe-table>
      <el-pagination :current-page="page" :page-sizes="[10, 20, 50, 100]" :page-size="limit" :total="total"
                     layout="total, sizes, prev, pager, next, jumper" @size-change="pageSizeChangeHandle"
                     @current-change="pageCurrentChangeHandle">
      </el-pagination>
      </div>
      <!-- 弹窗, 新增 / 修改 -->
      <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
    </el-card>
  </div>
</template>
<script>
import mixinViewModule from '@/mixins/view-module'
import AddOrUpdate from './apiQueueLog-add-or-update'
export default {
  mixins: [mixinViewModule],
  data () {
    return {
      searchShow: true,
      mixinViewModuleOptions: {
        getDataListURL: '/queue/apiQueueLog/page',
        getDataListIsPage: true,
        deleteURL: '/queue/apiQueueLog',
        deleteIsBatch: true,
        exportURL: '/queue/apiQueueLog/export'
      },
      dataForm: {
        queueName: '',
        msgBizKey: '',
        feedStatus: ''
      }
    }
  },
  components: {
    AddOrUpdate
  },
  methods: {
    // 新增 / 修改
    addOrUpdateHandle (row) {
      let id
      if (row) {
        id = row.id
      }
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.addOrUpdate.dataForm.id = id
        this.$refs.addOrUpdate.init()
      })
    }
  }
}
</script>
